<?php
require_once "ModelBase.php";

class Sms extends TTEvent_Table_Abstract
{
	protected $_name = 'tamtay_event_sms';
	protected $_primary = 'smsid';
	
	// Get resource math with sms
	public function getEventSms($eid, $thid=0, $pid=0, $type=0){
		$sql = "";
		
		
		$cond = " ev.eid=? ";
		$valArr = array($eid);
		if(is_numeric($thid) && $thid>0){
			$cond .= " AND ev.thid=? ";
			$valArr[] = $thid;
			if(is_numeric($pid) && $pid>0){
				$cond .= " AND ev.pid=? ";
				$valArr[] = $pid;
			}
			
		}
		if(is_numeric($type) && $type>0){
			$cond .= " AND ev.vote_type=? ";
			$valArr[] = $type;
		}
		
		$sql="SELECT DISTINCT 
					sms.sms AS vote_sms_count, sms.sbd, ev.voteid, ev.thid, ev.pid, sms.rid
				FROM tamtay_event_sms sms
					INNER JOIN tamtay_event_vote ev ON sms.voteid=ev.voteid AND ".$cond."
				ORDER BY ev.thid, ev.pid";
		
		
		$db = $this->getSlaveDB();
		$rs = $db->query($sql, $valArr);
		$eventPhotos = array();
		while($row = $rs->fetch()){
			$eventPhotos[] = $row;
		}
		
		return $eventPhotos;
	}
}

